<?php
namespace  My\Controller;
use Utuo\BackgroundController;
use Utuo\Form;

class LostFoundController extends BackgroundController
{
	public function _initialize() {
		$this->setControllerTitle("失物招领管理");
		$this->setActionTitle(array(
				'index' => '失物招领列表',
				'show' => '失物招领详情',
				'recycle' => '回收站'
		));
		$this->setActionNav(array(
				'index',
				'recycle'
		));
		$this->setLinkNav("全部", U("LostFound/index"));
		foreach (D("LostFound")->status as $k => $v) {
			$this->setLinkNav($v, U("LostFound/index?status=".$k));
		}
	}
	public function getLists($is_deleted,$status=null){
		$condation=array(
		     'sid'=>$this->aid,
		     'status'=>1,
			'is_deleted'=>$is_deleted	
		);
		$status!==null and $condation['status']=$status;
		$lostFound=D('LostFound')->where($condation)->page($this->getPage(),$this->getPageSize())->select();
		
		foreach ($lostFound as &$v){
			$v['statusOptions'] = Form::getOption(D("LostFound")->status, $v['status']);
		}
		$count=D('LostFound')->where($condation)->count();
		$this->showPage($count, $this->getPageSize());
		$this->assign('lostFound',$lostFound)->display();
	}
	public  function showAction($id){
		$lostFound=D('LostFound')->find($id);
		$this->assign("lostFound",$lostFound)->display();
	}
	
	 // 设置审核状态
	public function setStatusAction() {
		$id = I("id", 0, "intval");
		$status = I("status", 0, "intval");
		$d = M("LostFound");
		if (false!==$d->where("id={$id}")->setField("status", $status)) {
			$this->ajaxSuccess();
		} else {
			$this->ajaxError($d->getError());
		}
	} 
}